package com.example.opengl.base

import android.content.Context
import com.android.baselibrary.app.MainApplication
import java.io.BufferedReader
import java.io.InputStreamReader
import java.lang.Exception

/**
 * @author: Mr.You
 * @create: 2023-07-18 16:55
 * @description:
 **/
class TextResourceReader {
    companion object {
        fun readTextFileFormResource(context: Context = MainApplication.mainApplication, resourceId: Int):String {
            val stringBuffer = StringBuffer()
            try {
                val inputStream = context.resources.openRawResource(resourceId)
                val inputStreamReader = InputStreamReader(inputStream)
                val bufferedReader = BufferedReader(inputStreamReader)
                var nextLine:String? = null
             /*   while ((nextLine = bufferedReader.readLine()) !=null){
                    stringBuffer.append(nextLine)
                    stringBuffer.append("\n") //TODO 单双引号
                }*/

                while ((bufferedReader.readLine().also { nextLine = it }) !=null) {
                    stringBuffer.append(nextLine);
                    stringBuffer.append('\n');
                }
            }catch (e:Exception){

            }

            return  stringBuffer.toString()
        }
    }
}